package com.ruoyi.account.service.impl;

import java.util.List;
import java.util.Map;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.CxSelect;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.db.domain.SpecialCostomInfo;
import com.ruoyi.db.mapper.SpecialCostomInfoMapper;
import com.ruoyi.db.mapper.SpecialDataInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.db.mapper.AccountItemSpecialMapper;
import com.ruoyi.db.domain.AccountItemSpecial;
import com.ruoyi.account.service.IAccountItemSpecialService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 机构账户信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-07-28
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class AccountItemSpecialServiceImpl implements IAccountItemSpecialService 
{
    @Resource
    private AccountItemSpecialMapper accountItemSpecialMapper;
    @Resource
    private SpecialCostomInfoMapper specialCostomInfoMapper;

    /**
     * 查询机构账户信息
     * 
     * @param id 机构账户信息主键
     * @return 机构账户信息
     */
    @Override
    public AccountItemSpecial selectAccountItemSpecialById(String id)
    {
        return accountItemSpecialMapper.selectAccountItemSpecialById(id);
    }

    /**
     * 查询机构账户信息列表
     * 
     * @param accountItemSpecial 机构账户信息
     * @return 机构账户信息
     */
    @Override
    public List<AccountItemSpecial> selectAccountItemSpecialList(AccountItemSpecial accountItemSpecial)
    {
        return accountItemSpecialMapper.selectAccountItemSpecialList(accountItemSpecial);
    }

    /**
     * 查询机构账户信息列表
     *
     * @param accountItemSpecial 机构账户信息
     * @return 机构账户信息
     */
    @Override
    public List<Map<String, Object>> selectAccountItemSpecialListMap(AccountItemSpecial accountItemSpecial)
    {
        return accountItemSpecialMapper.selectAccountItemSpecialListMap(accountItemSpecial);
    }

    /**
     * 新增机构账户信息
     * 
     * @param accountItemSpecial 机构账户信息
     * @return 结果
     */
    @Override
    public int insertAccountItemSpecial(AccountItemSpecial accountItemSpecial)
    {

        // 查询机构信息
        SpecialCostomInfo costomInfo = specialCostomInfoMapper.selectSpecialCostomInfoById(String.valueOf(accountItemSpecial.getInfoId()));
        if (ObjectUtil.isEmpty(costomInfo)){
            return -1;
        }

        accountItemSpecial.setAccountName(costomInfo.getName());
        accountItemSpecial.setInfoId(costomInfo.getId());
        accountItemSpecial.setInfoName(costomInfo.getName());
        accountItemSpecial.setDeptId(costomInfo.getDeptId());
        accountItemSpecial.setOwnerId(costomInfo.getOwnerUserId());
        accountItemSpecial.setOwnerName(costomInfo.getOwnerUsername());

        accountItemSpecial.setCreateTime(DateUtils.getNowDate());
        return accountItemSpecialMapper.insertAccountItemSpecial(accountItemSpecial);
    }

    /**
     * 修改机构账户信息
     * 
     * @param accountItemSpecial 机构账户信息
     * @return 结果
     */
    @Override
    public int updateAccountItemSpecial(AccountItemSpecial accountItemSpecial)
    {
        accountItemSpecial.setUpdateTime(DateUtils.getNowDate());
        return accountItemSpecialMapper.updateAccountItemSpecial(accountItemSpecial);
    }

    /**
     * 批量删除机构账户信息
     * 
     * @param ids 需要删除的机构账户信息主键
     * @return 结果
     */
    @Override
    public int deleteAccountItemSpecialByIds(String ids)
    {
        return accountItemSpecialMapper.deleteAccountItemSpecialByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除机构账户信息信息
     * 
     * @param id 机构账户信息主键
     * @return 结果
     */
    @Override
    public int deleteAccountItemSpecialById(String id)
    {
        return accountItemSpecialMapper.deleteAccountItemSpecialById(id);
    }

    @Override
    public List<CxSelect> selectInfoSelectList(AccountItemSpecial accountItemSpecial) {
        return accountItemSpecialMapper.selectInfoSelectList(accountItemSpecial);
    }

    @Override
    public List<Map<String, Object>> selectAccountInfoMapList(AccountItemSpecial accountItemSpecial) {
        return accountItemSpecialMapper.selectAccountInfoMapList(accountItemSpecial);
    }

    @Override
    public AccountItemSpecial selectAccountItemSpecialByDeptId(Long deptId) {
        return accountItemSpecialMapper.selectAccountItemSpecialByDeptId(deptId);
    }
}
